package com.zggk.iroad.downdialog;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.view.ViewGroup.LayoutParams;
import com.zggk.iroad.R;
import com.zggk.iroad.util.MyUtils;

public class DownDialog {
    private Dialog dialog;// 对话框
    public TextView txtOk;//确定按钮
    public TextView txtTitle;//提示内容文本

    public Dialog getDialog() {
        return dialog;
    }

    /**
     * 构造方法
     *
     * @param context    使用该对话框的类
     * @param title      标题
     * @param okStr      确定按钮文字
     * @param cancelStr  取消按钮文字
     * @param okListener 确定按钮点击监听
     */
    public DownDialog(Context context, String title,
                      String okStr, String cancelStr, final DownBtnListener okListener) {
        dialog = new Dialog(context, R.style.DowmDialogStyle);
        dialog.setCanceledOnTouchOutside(false);
        View viewDialog = LayoutInflater.from(context).inflate(
                R.layout.down_dialog, null);
        LayoutParams params = new LayoutParams(MyUtils.dp2px(context, 300), LayoutParams.WRAP_CONTENT);
        dialog.addContentView(viewDialog, params);
        txtTitle = (TextView) viewDialog.findViewById(R.id.title_text);
        txtOk = (TextView) viewDialog.findViewById(R.id.ok_btn);
        txtTitle.setText(title);
        txtOk.setText(okStr);
        // 确定按钮
        txtOk.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                okListener.CommOkBtnClick();
                if (dialog.isShowing()) {
                    dialog.cancel();
                }
            }
        });
    }

    /**
     * 设置对话框的提示内容
     */
    public void setWarmTitle(String title) {
        txtTitle.setText(title);
    }

    /**
     * 显示
     */
    public void show() {
        dialog.show();
    }

    /**
     * 关闭
     */
    public void close() {
        dialog.cancel();
    }
}

